#include "includes.h"


unsigned long int num;


int main(void){
	
	char uart_temp;
	char *command=malloc(3);
	char *option=malloc(2);
	char *temp,*temp1;
	temp=option;
	temp1=command;
	//interrupt init
	interrupt_init();
	// lcd initialization
	lcd_init(LCD_DISP_ON_CURSOR_BLINK); 
	//buzzer initialization
	buzzer_init();
	pwm_init();
	//serial interface init
	USART_init();
	
	USART_Transmit_s("DevBoard connected...");
	
    buzzer(50);
	asm("sei");
	
	
	while(1){
	//temp2lcd();
		if(USART_counter==6){
			strcpy(command,(char*)USART_buffer); 
			*option = USART_buffer[4];
			*(option++) = USART_buffer[5];
			option = temp;
			lcd_clrscr();
			if(!strncmp(command,"get",3)){
					lcd_puts(" cmd:get\n");	
					
							
				if(!strncmp(option-1,"t1",2)){
						lcd_puts("t1: ");
						read_temperature();
					
				}	
			
				if(!strncmp(option-1,"t2",2)){
						lcd_puts("t2: ");
						adc_init(0);	
						adc_lcd();
				}		
				
				if(!strncmp(option-1,"t3",2)){
						lcd_puts("t3: ");
						
				}
				
				if(!strncmp(option-1,"t4",2)){
					if(USART_buffer[6] == '0')
					{
						lcd_puts("Buzzer off");
						pwm_off();
					}
					else
					{
					lcd_puts("t4: ");
					pwm_init();
					lcd_putc(USART_buffer[6]);
					uart_temp = USART_buffer[6];
					switch(uart_temp)
					{
						case '1':
								uart_temp = 10;
						break;
						
						case '2':
								uart_temp = 60;
						break;
						
						case '3':
								uart_temp = 120;
						break;
						
						case '4':
								uart_temp = 150;
						break;
						
						case '5':
								uart_temp = 200;
						break;
						
						default: uart_temp = 0;
						break;
					}
					//uart_temp /= 0x40;
					//uart_temp *= 10;
					pwm_setduty((char)uart_temp);
					}					
					
				}
			}
			strcpy((char*)USART_buffer,"");		
			command = temp1;
			option = temp;
			USART_counter=0;
			_delay_ms(500);
		}		
    }
    return 0;
}
